﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Xml.Serialization;
using System.IO;

namespace Mimoza.UpdatePlugin
{
    public class UpdatePluginData
    {
        public Guid UpdateId
        {
            get { return m_updateId; }
            set { m_updateId = value; }
        }

        public string OSName
        {
            get { return m_OSName; }
            set { m_OSName = value; }
        }

        public string ModelName
        {
            get { return m_ModelName; }
            set { m_ModelName = value; }
        }

        public string Version
        {
            get { return m_version; }
            set { m_version = value; }
        }

        public void Fill(Mimoza.ObjectLayer.Update update)
        {
            UpdateId = update.ID;
            OSName = update.OS;
            ModelName = update.Model;
            Version = update.Version;
        }

        public string Serialize()
        {
            XmlSerializer serializer = new XmlSerializer(typeof(UpdatePluginData));
            TextWriter text = new StringWriter();
            serializer.Serialize(text, this);
            return text.ToString();
        }

        public static UpdatePluginData Deserialize(string data)
        {
            XmlSerializer deserializer = new XmlSerializer(typeof(UpdatePluginData));
            using (TextReader text = new StringReader(data))
            {
                return deserializer.Deserialize(text) as UpdatePluginData;
            }
        }

        Guid m_updateId; 
        
        string m_ModelName;
        string m_OSName;
        string m_version;
    }
}
